#include <pcap.h>
#include <stdio.h>
#include <string.h>
#include <netinet/ip.h>

int sock;
struct sockaddr_in addr;

void getPacket(u_char * arg, const struct pcap_pkthdr * pkthdr, const u_char * packet)  
{  
    sendto(sock, packet + 14, pkthdr->len - 14, 0, (struct sockaddr*)&addr, sizeof(addr));
}  

int main(int argc, char *argv[])  
{  
    char errBuf[PCAP_ERRBUF_SIZE];  

    if (argc < 4)
    {
        printf("usage: %s eth0 192.168.1.25 81\n", argv[0]);
        return 1;
    }

    sock = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP);
    memset(&addr, 0, sizeof(addr));
    addr.sin_family = AF_INET;
    addr.sin_addr.s_addr = inet_addr(argv[2]);
    addr.sin_port = htons(atoi(argv[3]));
    
    pcap_t * pcap = pcap_open_live(argv[1], 65536, 0, 0, errBuf);

    struct bpf_program filter;  
    pcap_compile(pcap, &filter, "dst port 80", 1, 0);  
    pcap_setfilter(pcap, &filter);  
  
    pcap_loop(pcap, -1, getPacket, NULL);  

    pcap_close(pcap);  
    close(sock);
  
    return 0;  
}  
